/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo360.mobilesafe.utils;

import android.content.Context;
import dalvik.system.DexClassLoader;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class DexUtils {
    private static final String TAG = "DexUtils";

    public static DexClassLoader getDexClassLoader(Context paramContext, String paramString1, String paramString2) {
        return getDexClassLoader(paramContext, paramString1, paramString2, true);
    }

    public static DexClassLoader getDexClassLoader(Context paramContext, String paramString1, String paramString2,
            boolean paramBoolean) {
        DexClassLoader localDexClassLoader = null;
        try {
            String str = paramContext.getFilesDir().getAbsolutePath();
            File localFile = new File(paramContext.getFilesDir(), paramString1);
            if (!(AssetsUtils.quickExtractTo(paramContext, paramString1, str, paramString1, paramBoolean, null)))
                return null;
            if (localFile.exists()) {
                localDexClassLoader = new DexClassLoader(localFile.getAbsolutePath(), str, null,
                        paramContext.getClassLoader());
                if (localDexClassLoader == null)
                    ;
            }
        } catch (Exception localException) {}
        return localDexClassLoader;
    }

    public static final Object get_param_static(DexClassLoader paramDexClassLoader, String paramString1,
            String paramString2) {
        try {
            Class localClass = paramDexClassLoader.loadClass(paramString1);
            Field localField = localClass.getDeclaredField(paramString2);
            return localField.get(null);
        } catch (Exception localException) {}
        return null;
    }

    public static final void set_param_static(DexClassLoader paramDexClassLoader, String paramString1,
            String paramString2, Object paramObject) {
        try {
            Class localClass = paramDexClassLoader.loadClass(paramString1);
            Field localField = localClass.getDeclaredField(paramString2);
            localField.setAccessible(true);
            localField.set(null, paramObject);
        } catch (Exception localException) {}
    }

    public static final Field get_param_static_field(DexClassLoader paramDexClassLoader, String paramString1,
            String paramString2) {
        try {
            Class localClass = paramDexClassLoader.loadClass(paramString1);
            Field localField = localClass.getDeclaredField(paramString2);
            localField.setAccessible(true);
            return localField;
        } catch (Exception localException) {}
        return null;
    }

    public static final Class get_class_class(DexClassLoader paramDexClassLoader, String paramString) {
        try {
            return paramDexClassLoader.loadClass(paramString);
        } catch (Exception localException) {}
        return null;
    }

    public static final Object get_class_enum(DexClassLoader paramDexClassLoader, String paramString1,
            String paramString2) {
        try {
            Object localObject1 = null;
            Class localClass = paramDexClassLoader.loadClass(paramString1);
            if (localClass.isEnum())
                for (Object localObject2 : localClass.getEnumConstants()) {
                    if (!(((Enum) localObject2).name().equals(paramString2)))
                        continue;
                    localObject1 = localObject2;
                    break;
                }
            return localObject1;
        } catch (Exception localException) {}
        return null;
    }

    public static final Method get_class_method(DexClassLoader paramDexClassLoader, String paramString1,
            String paramString2, Class[] paramArrayOfClass) {
        try {
            Class localClass1 = paramDexClassLoader.loadClass(paramString1);
            Class localClass2 = localClass1;
            while (localClass2 != Object.class)
                try {
                    Method localMethod = localClass2.getDeclaredMethod(paramString2, paramArrayOfClass);
                    localMethod.setAccessible(true);
                    return localMethod;
                } catch (Exception localException2) {
                    localClass2 = localClass2.getSuperclass();
                }
        } catch (Exception localException1) {}
        return null;
    }

    public static final Object get_class_static(Method paramMethod, Object[] paramArrayOfObject) {
        try {
            return paramMethod.invoke(null, paramArrayOfObject);
        } catch (Exception localException) {}
        return null;
    }

    public static final Object get_class_object(Object paramObject, Method paramMethod, Object[] paramArrayOfObject) {
        try {
            return paramMethod.invoke(paramObject, paramArrayOfObject);
        } catch (Exception localException) {}
        return null;
    }

    public static final Object get_object_varables(Object paramObject, String paramString) {
        Field localField = null;
        Class localClass1 = paramObject.getClass();
        Class localClass2 = localClass1;
        while (localClass2 != Object.class)
            try {
                localField = localClass2.getDeclaredField(paramString);
                return localField.get(paramObject);
            } catch (Exception localException) {
                localClass2 = localClass2.getSuperclass();
            }
        return null;
    }

    public static final void set_object_varables(Object paramObject1, String paramString, Object paramObject2) {
        Field localField = null;
        Class localClass1 = paramObject1.getClass();
        for (Class localClass2 = localClass1; localClass2 != Object.class; localClass2 = localClass2.getSuperclass())
            try {
                localField = localClass2.getDeclaredField(paramString);
                localField.set(paramObject1, paramObject2);
            } catch (Exception localException) {}
    }

    public static final Field get_object_varables_field(Object paramObject, String paramString) {
        Field localField = null;
        Class localClass1 = paramObject.getClass();
        Class localClass2 = localClass1;
        while (localClass2 != Object.class)
            try {
                localField = localClass2.getDeclaredField(paramString);
                return localField;
            } catch (Exception localException) {
                localClass2 = localClass2.getSuperclass();
            }
        return localField;
    }

    public static Object get_class_new(Constructor paramConstructor, Object[] paramArrayOfObject) {
        try {
            return paramConstructor.newInstance(paramArrayOfObject);
        } catch (Exception localException) {}
        return null;
    }

    public static Constructor get_class_contructor(ClassLoader paramClassLoader, String paramString,
            Class[] paramArrayOfClass) {
        try {
            Class localClass = paramClassLoader.loadClass(paramString);
            return localClass.getDeclaredConstructor(paramArrayOfClass);
        } catch (Exception localException) {}
        return null;
    }
}